//
// Created by martin on 2/7/22.
//

#ifndef MUDUO_PROCESSINFO_H
#define MUDUO_PROCESSINFO_H

#include "muduo/base/StringPiece.h"
#include "muduo/base/Timestamp.h"

#include <sys/types.h>
#include <vector>

namespace muduo
{
namespace ProcessInfo
{

pid_t pid(); // get process identification
string pidString(); // get string format of rocess identification (pid())
uid_t uid(); // get the real user_ ID
string username();
uid_t euid(); // get the effective user_ ID
Timestamp startTime();
int clockTickPerSecond();
int pageSize();
bool isDebugBuild();

string hostname();
string procname();
StringPiece procname(const string& stat);

/* read /proc/self/status */
string procStatus();

/* read /proc/self/stat */
string procStat();

/* read /proc/self/task/tid/stat */
string threadStat();

/* readlink /proc/self/exe */
string exePath();

int openedFiles();
int maxOpenFiles();

struct CpuTime
{
    double userSeconds;
    double systemSeconds;

    CpuTime() : userSeconds(0.0), systemSeconds(0.0) { }

    double total() const { return userSeconds + systemSeconds; }
};

struct CpuTime cpuTime();

int numThreads();
std::vector<pid_t> threads();

} // namespace ProcessInfo
} // namespace muduo

#endif //MUDUO_PROCESSINFO_H
